
#pragma once

#include <ql/config.h>

#include <stddef.h>

#ifdef __cplusplus
extern "C"
{
#endif

#if defined(QL_ENABLE_MEM_DEBUG)

#if defined(_MSC_VER)

#include <crtdbg.h>
#include <string.h>

#define ql_malloc(s)        _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
#define ql_realloc(p, s)    _realloc_dbg( p, s, _NORMAL_BLOCK, __FILE__, __LINE__ )
#define ql_free(p)          _free_dbg( p, _NORMAL_BLOCK )

void * ql_dbg_mallocz_impl( size_t s, const char * file, int line );
#define ql_mallocz(s)       ql_dbg_mallocz_impl( s, __FILE__, __LINE__ )

void ql_dump_mem_leaks();

#else
#error debug allocator has not been implemented for such a compiler
#endif

#else

void * ql_malloc(size_t size);
void * ql_mallocz(size_t size);
void * ql_realloc(void * ptr, size_t size);
void ql_free(void * ptr);

#define ql_dump_mem_leaks()

#endif

#ifdef __cplusplus
}
#endif
